package com.huluobo.a2207parkdemo.adapter

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.gson.Gson
import com.huluobo.a2207parkdemo.R
import com.huluobo.base.bean.PPointBean
import com.huluobo.base.bean.PatrolBeanItem

/**
 *  Created by LC on 2024/11/26.
 */
class PatrolAdapter : BaseQuickAdapter<PatrolBeanItem, BaseViewHolder>(R.layout.item_patrol) {
    override fun convert(helper: BaseViewHolder, item: PatrolBeanItem) {
        helper.setText(R.id.item_patrol_group_tv, "第${item.pGroupId}小队")
        helper.setText(R.id.item_patrol_start_time_now_tv, item.pStart)
        helper.setText(R.id.item_patrol_end_time_now_tv, item.pEnd)
        helper.setText(R.id.item_patrol_time_now_tv, item.pTime)

        val recyclerView = helper.getView<RecyclerView>(R.id.item_patrol_rv)
        recyclerView.layoutManager = GridLayoutManager(context, 2)
        val adapter = PointAdapter()
        recyclerView.adapter = adapter

        if (!item.pPoint.isNullOrEmpty()) {
            if (item.pPoint.substring(0, 1) == "[") {
                val list = Gson().fromJson(item.pPoint, PPointBean::class.java)
                adapter.data.clear()
                adapter.data.addAll(list)
                adapter.notifyDataSetChanged()
            }
        }
    }
}